<style>
.layui-form-pane .layui-form-label{width:auto;}
.layui-form-item{margin-bottom: 0px;}
.role_style{background-color:#00CCCC;}
</style>
<div class="fixed-bar">
    <form class="layui-form layui-form-pane fixed-bar-form" action="{:url()}" method="get" id="hisi-table-search">
        <div class="layui-form-item">
         
         <div class="layui-inline">
            <label class="layui-form-label">关键字</label>
             <div class="layui-input-inline">
                 <input type="text" name="name" lay-verify="" placeholder="标签名称关键字" class="layui-input">
             </div>
         </div>
         <div class="layui-inline">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">搜索</button>
         </div>
        </div>
    </form>
</div>

<table id="dataTable"></table>
{include file="system@block/layui" /}

<script type="text/html" id="toolbar">
    <div class="layui-btn-group fl">
        <a href="{:url('searchLabelList')}?use_action=edit_search_label" class="layui-btn layui-btn-primary 
		layui-btn-sm layui-icon layui-icon-add-circle-fine hisi-iframe" hisi-data="{width: '700px', height: '660px'}" title="自定义搜索标签">&nbsp;添加搜索标签</a>
    </div>
</script>
<script type="text/html" title="操作按钮模板" id="buttonTpl">
	<a href="{:url('searchLabelList')}?use_action=edit_search_label&id={{ d.id }}" class="layui-btn layui-btn-xs layui-btn-normal hisi-iframe" hisi-data="{width: '700px', height: '660px'}" title="修改">修改</a>
	<a href="{:url('searchLabelList')}?use_action=del_search_label&id={{ d.id }}&val=-1"  hisi-data="{refresh: true}" class="layui-btn layui-btn-xs layui-btn-danger j-tr-del">删除</a>
</script>
<script type="text/html" id="useOrders">
    {{ d.use_orders_30d }} / 
	{{# if(d.use_orders > 0){ }}
		<a href="{:url('history')}?id={{ d.id }}" class="hisi-iframe blue" title="使用产品记录">{{ d.use_orders }}</a>
	{{# }else{ }}
		0
	{{# } }}
</script>
<script type="text/html" title="" id="showDataTpl">
	<input type="checkbox" name="status[{{ d.id }}]" lay-filter="showStatus" value="{{ d.id }}" lay-skin="switch" lay-text="开|关" {{# if(d.show_status > 0){ }}checked=""{{#  } }}>
</script>
<script type="text/html" id="useTimeTpl">
    <div>{{layui.util.toDateString(d.use_time * 1000) }}</div>
</script>

<script type="text/javascript">
    layui.use(['table', 'tool','form','jquery'], function() {
        var table = layui.table,form = layui.form;
		var $ = layui.jquery;
        table.render({
            elem: '#dataTable'
            ,url: '{:url()}' //数据接口
            ,page: true //开启分页
            ,skin: 'row'
            ,even: true
            ,limit: 20
            ,limits: [20,50,100,150,200]
            ,text: {
                none : '暂无相关数据'
            }
            ,toolbar: '#toolbar'
            ,defaultToolbar: ['filter', 'exports', 'print']
            ,cols: [[ //表头
                {field: 'id', title: '编号',width: 55}
                ,{field: 'label_name', title: '标签名称'}
                ,{field: 'material_sku', title: '搜索时间范围',width: 150, templet:function(d){return '<span class="copy-item">'+d.search_end_time+'</span>/'+d.search_history;}}
				,{field: 'marerialStatus_str', title: '搜索物料状态'}
				,{field: 'm_status_logic', title: '状态关系',width: 90,templet:function(d){return d.m_status_logic=='and'?'并且':'或者';}}
				,{field: 'materialtype_str', title: '显示物料',width: 80}
				,{field: 'order_type', title: '单类',width: 80}
                ,{field: 'factory_ids_str', title: '搜索工厂',width: 160}
				,{field: 'visit_role_ids', title: '可浏览角色及成员',width: 130,templet:function(d){return '<span class="role_style">'+d.visit_roles_str+'</span> '+d.visit_admins_str;}}
				,{field: 'admin_user', title: '最后编辑',width: 70}
                ,{field: 'create_time', title: '更新时间',width: 100,templet:function(d){ if(d.create_time>0){ 
					return"<span title="+layui.util.toDateString(d.update_time * 1000,'yyyy-MM-dd HH:mm')+">"+layui.util.toDateString(d.update_time * 1000,'MM-dd HH:mm')+"</span>";
				}else{
						return '--';
				}}}
                ,{field: 'show_status', title: '状态',width: 65,templet:'#showDataTpl'}
                ,{field: '', title: '操作', templet: '#buttonTpl', fixed: 'right',width: 100}
            ]]
        });
		form.on('switch(showStatus)', function(data){
		  console.log(data.elem.checked); //开关是否开启，true或者false
		  	var label_id=data.value;
		  	var show_status=data.elem.checked==true ? 1 : 0;
			console.log(data.value);
			$.ajax({
			   type: "POST",
			   url: "{:url('addSearchLabel')}",
			   data: "show_status="+show_status+"&id="+label_id,
			   dataType:"json",
			   success: function(res){
				  if (res.code == 1) {
					 layer.msg(res.msg, {icon: 1});
				  } else {
					 layer.msg(res.msg, {icon: 2,anim: 6});
				  }
			   }
			});  
		});  
    });
</script>